package com.ideaaedi.springcloud.jd.user.controller.sys;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSort;
import com.ideaaedi.springcloud.jd.commonds.entity.PageInfo;
import com.ideaaedi.springcloud.jd.commonds.entity.Result;
import com.ideaaedi.springcloud.jd.commonds.entity.user.vo.req.SysDeptAddReqVO;
import com.ideaaedi.springcloud.jd.commonds.entity.user.vo.req.SysDeptListReqVO;
import com.ideaaedi.springcloud.jd.commonds.entity.user.vo.req.SysDeptUpdateReqVO;
import com.ideaaedi.springcloud.jd.commonds.entity.user.vo.resp.SysDeptDetailRespVO;
import com.ideaaedi.springcloud.jd.commonds.entity.user.vo.resp.SysDeptListRespVO;
import com.ideaaedi.springcloud.jd.user.service.SysDeptService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.constraints.NotNull;

/**
 * 系统 - 部门
 *
 * @author <font size = "20" color = "#3CAA3C"><a href="https://gitee.com/JustryDeng">JustryDeng</a></font> <img
 * src="https://gitee.com/JustryDeng/shared-files/raw/master/JustryDeng/avatar.jpg" />
 * @since 2021.0.1.A
 */
@Slf4j
@RestController
@ApiSort(value = 8)
@RequestMapping("/sys-dept")
@Api(value = "系统-组织架构", tags = {"系统-组织架构"})
public class SysDeptController {
    
    @Resource
    private SysDeptService sysDeptService;
    
    /**
     * 新增
     *
     * @param req 参数
     *
     * @return 新增的部门详情
     */
    @PostMapping("/add")
    @ApiOperation(value = "新增")
    @ApiOperationSupport(order = 1)
    public Result<SysDeptDetailRespVO> add(@Validated @RequestBody SysDeptAddReqVO req) {
        return Result.success(sysDeptService.add(req));
    }
    
    /**
     * 删除
     *
     * @param deptId 部门id
     *
     * @return 删除了的部门详情
     */
    @ApiOperation(value = "删除")
    @ApiOperationSupport(order = 2)
    @DeleteMapping("/delete/{deptId}")
    public Result<SysDeptDetailRespVO> delete(@ApiParam(value = "部门id", required = true)
                                              @NotNull(message = "deptId不能为空") @PathVariable("deptId") Integer deptId) {
        return Result.success(sysDeptService.delete(deptId));
    }
    
    /**
     * 更新
     *
     * @param req 参数
     *
     * @return 修改后的部门详情
     */
    @PutMapping("/update")
    @ApiOperation(value = "更新")
    @ApiOperationSupport(order = 3)
    public Result<SysDeptDetailRespVO> update(@Validated @RequestBody SysDeptUpdateReqVO req) {
        return Result.success(sysDeptService.update(req));
    }
    
    /**
     * 列表
     *
     * @param req 参数
     *
     * @return 部门集合
     */
    @PostMapping("/list")
    @ApiOperation(value = "列表")
    @ApiOperationSupport(order = 4)
    public Result<PageInfo<SysDeptListRespVO>> list(@Validated @RequestBody SysDeptListReqVO req) {
        return Result.success(sysDeptService.list(req));
    }
    
    /**
     * 详情
     *
     * @param deptId 部门id
     *
     * @return 部门详情
     */
    @ApiOperation(value = "详情")
    @GetMapping("/detail/{deptId}")
    @ApiOperationSupport(order = 5)
    public Result<SysDeptDetailRespVO> detail(@ApiParam(value = "部门id", required = true)
                                              @NotNull(message = "deptId不能为空") @PathVariable("deptId") Integer deptId) {
        return Result.success(sysDeptService.detail(deptId));
    }
}
